package com.boang.web;

import com.boang.po.Student;
import com.boang.util.DBUtil;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

/*
  @author: 13813
  @date: 2024/7/11 15:42
*/
@WebServlet("/h03")
public class ServletDemo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        RequestDispatcher dispatcher = req.getRequestDispatcher("stu.jsp");
//        req.setAttribute("name", "zhangsan");
//        req.setAttribute("age", "20");
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(100, "张三"));
        list.add(new Student(200, "李四"));
        list.add(new Student(300, "王五"));
        req.setAttribute("stus", list);
        dispatcher.forward(req, resp);
        try {
            System.out.println(DBUtil.getConn());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
//        resp.getWriter().write("<h1>AAA</h1><h2>BBB</h2>");
    }
}
